package com.autonavi.yunda.yunji.controller.request;

import com.autonavi.yunda.yunji.common.exception.AmapPreconditions;
import com.autonavi.yunda.yunji.core.enums.RoleType;
import com.autonavi.yunda.yunji.core.enums.UserPermission;
import com.autonavi.yunda.yunji.core.model.dto.UserDTO;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author cizhong.wcs
 * @date 2023/9/6 10:22
 */
@Data
public class UserRequest {
    private String userId;
    private String nickName;
    private String lastName;
    private RoleType userRole;
    private List<String> projectIds;
    private List<UserPermission> permissions;

    public UserDTO toUpdateDTO() {
        AmapPreconditions.checkNotBlank(userId);

        return UserDTO.builder()
                .userId(userId)
                .userRole(userRole)
                .lastName(lastName)
                .nickName(nickName)
                .permissions(CollectionUtils.isEmpty(permissions) ?
                        new ArrayList<>() : permissions.stream().map(Enum::name).collect(Collectors.toList()))
                .build();
    }
}
